package com.webshop.Dao;

import com.webshop.domain.Cart;

import java.util.Iterator;
import java.util.List;

public class CartDao {
    public static void addCart(Cart cart, List<Cart> carts){
        Iterator iterator = carts.iterator();
        while (iterator.hasNext()){
            Cart c = (Cart)iterator.next();
            if (c.getId() == cart.getId()){
                cart.setNum(c.getNum()+cart.getNum());
                carts.remove(c);
                carts.add(cart);
                return;
            }
        }
        carts.add(cart);
        return;
    }
}
